package com.github.yealove.configgen.mapper;

import com.github.yealove.configgen.model.Template;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface TemplateMapper {

    @Select("select id, name, content, file_type fileType, nacos_group nacosGroup, nacos_namespace nacosNamespace, version, create_time createTime from cg_template order by name,version asc")
    List<Template> getAllTemplate();

    @Insert("insert into cg_template(name, content, file_type, nacos_group, nacos_namespace, version, create_time) values (#{name}, #{content}, #{fileType}, #{nacosGroup}, #{nacosNamespace}, #{version}, now())")
    void addTemplate(Template template);

    @Insert("update cg_template set content = #{content}, name = #{name}, file_type = #{fileType}, nacos_group = #{nacosGroup}, nacos_namespace = #{nacosNamespace}, version = #{version} where id = #{id}")
    void updateTemplate(Template template);

    @Select("select id, name, content, file_type fileType, nacos_group nacosGroup, nacos_namespace nacosNamespace, version, create_time createTime from cg_template where id = #{templateId}")
    Template getTemplateById(int templateId);
}
